<?php

namespace App\Listeners;

use App\Events\MasterPunished;
use App\Models\OrderComplain;
use App\Services\IMasterLogService;
use App\Services\ISystemTaskService;
use App\Services\IWalletService;
use DB;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;

class MasterPunishedListener implements ShouldQueue
{

    use InteractsWithQueue;

    public $queue = 'finance';

    public $tries = 3;

    public $timeout = 30;

    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @return void
     */
    public function handle(MasterPunished $event)
    {
        $complain = OrderComplain::find($event->complain_id);
        if(!$complain){
            throw new \Exception('miss complain');
        }

        $ret = resolve(ISystemTaskService::class)->complainPunish($complain->oc_id,$event->amount);
        if(!$ret){
            throw new \Exception('complain punish fail');
        }
    }

    public function failed(MasterPunished $event, \Exception $exception)
    {
        //
    }
}
